package com.congee02;

import java.util.Arrays;

public class Jump {

    public int jump(int... nums) {
        Arrays.fill(cache, -1);
        return process(nums, nums.length, 0);
    }

    private int[] cache = new int[10001];
    private int process(int[] nums, int length, int index) {
        if (index == length - 1) {
            return 0;
        }
        if (cache[index] != -1) {
            int min = Integer.MAX_VALUE >>> 1;
            for (int j = 1 ; j <= nums[index] && index + j < length ; j ++ ) {
                min = Math.min(min, process(nums, length, index + j));
            }
            cache[index] = 1 + min;
        }
        return cache[index];
    }

    private void change(int... nums) {
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > 2) {
                nums[i] = 3;
            }
        }
    }

    private int[] nums(int... x) {
        return x;
    }

    public static void main(String[] args) {
        Jump s = new Jump();
        int[] x = s.nums(5, 6, 4, 4, 6, 9, 4, 4, 7, 4, 4, 8, 2, 6, 8, 1, 5, 9, 6, 5, 2, 7, 9, 7, 9, 6, 9, 4, 1, 6, 8, 8, 4, 4, 2, 0, 3, 8, 5);
        s.change(x);
        System.out.println(Arrays.toString(x));
        System.out.println(s.jump(x));
    }

}
